<template>
  <div class="login-form">
    <div class="login-box">
      <!-- <img :src="bkImg" style="height: 100%; flex-shrink: 0" /> -->
      <div class="login-input">
        <!--        <img :src="logoImg" />-->
        <div class="title">
          <h2>博鳌项目管理系统</h2>
          <h3><strong>Hello!</strong> 您好</h3>
          <h4>提供工作事项提醒，商业管理、项目管理、考勤管理 业务管理等功能，快速帮你分析数据。</h4>
        </div>
        <el-form :model="dataForm" :rules="dataRule" size="medium" ref="dataForm" @keyup.enter.native="dataFormSubmit()" style="width: 315px; margin-top: 6vh;">
          <el-col :span="24">
            <label>用户账号</label>
            <el-form-item prop="mobilePhone">
              <el-input v-model="dataForm.mobilePhone" style="width: 100%;" placeholder="帐号" autocomplete="off" prefix-icon="el-icon-name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <label>登录密码</label>
            <el-form-item prop="password">
              <el-input v-model="dataForm.password" style="width: 100%;" type="password" placeholder="密码" show-password autocomplete="off" prefix-icon="el-icon-password"></el-input>
            </el-form-item>
          </el-col>
          <el-button class="login-btn-submit" type="primary" style="width: 100%;"
            @click="dataFormSubmit()"
            :loading="isHttpLoading">
            登录
          </el-button>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import { SystemController } from '@/api';
import { mapMutations } from 'vuex';
import projectConfig from '@/core/config';
import { encrypt, setToken } from '@/utils';

export default {
  data () {
    return {
      bkImg: require('@/assets/img/login.png'),
      logoImg: require('@/assets/img/login_logo.png'),
      dataForm: {
        mobilePhone: '',
        password: ''
      },
      dataRule: {
        mobilePhone: [
          { required: true, message: '帐号不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ]
      },
      projectName: projectConfig.projectName
    };
  },
  methods: {
    dataFormSubmit () {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          let params = {
            loginName: this.dataForm.mobilePhone,
            password: encrypt(this.dataForm.password)
          };

          SystemController.login(this, params, null, {showMask: false}).then(data => {
            this.setMenuList(data.data.menuList);
            delete data.data.menuList;
            console.log(data.data)
            this.setUserInfo(data.data);
            setToken(data.data.tokenData);
            this.setCurrentMenuId(null);
            this.$router.replace({ name: 'main' });
          }).catch(e => {});
        }
      });
    },
    ...mapMutations(['setUserInfo', 'setMenuList', 'setCurrentMenuId'])
  },
  mounted () {
    this.setMenuList([]);
    this.setUserInfo({});
    setToken();
  }
};
</script>

<style lang="scss">
.login-form {
  width: 100vw;
  height: 100vh;
  background: #292D36;
  display: flex;
  justify-content: center;
  align-items: center;
  .login-box {
    display: flex;
    align-items: center;
    width: 100%;
    height: 100vh;
    padding: 0 7vh;
    border-radius: 3px;
    background: white url(../../assets/img/login-bj.png) no-repeat;
    background-size: 100% 118%;
    .login-input {
      position: absolute;
      top: 0;
      right: 0;
      height: 100%;
      width: 560px;
      display: flex;
      align-items: center;
      flex-direction: column;
      background: white url(../../assets/img/login-lfrom.png) no-repeat 120px -30px;
      background-size: 90% 105%;
      padding: 0 17vh;
      img {
        width: 356px;
        height: 42px;
        margin-top: 6vh;
      }
      label{margin-bottom: 5px;display: inline-block;}
      .title {
        color: #232323;
        font-size: 20px;
        margin-top: 2vh;
        text-align: left;
        h2,h3{font-weight: bold;}
        strong{font-size: 1.3em;}
        h4{color: #909399;font-size: 14px;}
      }
      /deep/.el-input__icon.el-icon-name {
        background: url(../../assets/img/login_name.png) no-repeat;
        margin: 5px 5px 0;
      }

      /deep/.el-input__icon.el-icon-password {
        background: url(../../assets/img/login_pass.png) no-repeat;
        margin: 5px 5px 0;
      }
    }
  }
}

.login-form .el-input__inner {
  height: 45px!important;
}

.login-form .el-button {
  height: 45px!important;
  font-size: 20px;
}
</style>
